package com.liliudong.cursormate.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.liliudong.cursormate.interceptor.CursorMateDataPermissionInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus配置
 *
 * @author Liudong.li
 * @version 1.0
 * @project cursor-mate
 * @date 2023/10/23 23:18:04
 */
@Configuration
@RequiredArgsConstructor
public class MybatisPlusConfiguration {

    /**
     * 插件配置
     *
     * @return {@link MybatisPlusInterceptor}
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        // 数据权限插件
        interceptor.addInnerInterceptor(new CursorMateDataPermissionInterceptor());
        return interceptor;
    }
}
